Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cash have all betas enabled when running in development mode #3135

Merged
merged 4 commits into from
May 27, 2021

Conversation

iwiznia
Copy link
Contributor

@iwiznia iwiznia commented May 25, 2021

Details

Fixed Issues

Fixes https://expensify.slack.com/archives/C03TQ48KC/p1621974182298000

Tests

  • Make the api User_GetBetas return []
  • Load the app before this change, make sure request money option is not shown in the big plus button
  • Load the app after this change, make sure request money option is shown in the big plus button

QA Steps

None, since this is just for dev

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

@iwiznia iwiznia requested a review from a team May 25, 2021 20:54
@iwiznia iwiznia self-assigned this May 25, 2021
@MelvinBot MelvinBot requested review from marcaaron and removed request for a team May 25, 2021 20:55
@@ -9,12 +11,14 @@ Onyx.connect({
callback: val => betas = val || [],
});

const isDevelopment = lodashGet(Config, 'ENVIRONMENT', CONST.ENVIRONMENT.DEV) === CONST.ENVIRONMENT.DEV;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking you should use getEnvironment() from the Environment module so that it will be cross-platform. However, that will also force this code to be async, which will be a pain to refactor. I believe it's only necessary to use getEnvironement() if you care about the difference between production and staging. Since you don't, it might be good to add a method to the Environment module called isDevelopment() which is a synchronous function (and then add method docs to explain why it's OK for it to be synchronous when getEnvironment() has to be async).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Why is that method returning a Promise?

Could we alternatively just use the __DEV__ global? It is being set here...

https://github.com/Expensify/Expensify.cash/blob/9a9099592330bc26d06408f34d76128718196eb4/config/webpack/webpack.dev.js#L37-L37

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Why is that method returning a Promise?

Why indeed, given it is getting a value from an already loaded object. Any objections to change that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mobile versions of the environment module need to make a network request to get the info about if it's in staging or production. That's why it needs to be async.

Copy link
Contributor

@marcaaron marcaaron May 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see now, because only the web app uses the staging env configs and the native apps always use production config, but we need to know if they are TestFlight or google play beta versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, true, did not notice that. So what is preferred to add a isDevelopment that's not async or use the __DEV__ global? If the latter, not sure how I grab that constant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel they are different concepts. It just happens that we are running in __DEV__ mode when we are using the development environment. But we could also be running the development environment (i.e. not staging or production) and not be "running in dev mode".

Regardless, I'd think we want the environment in this case since whether you are running in dev mode or not the betas would probably be enabled in the "development environment".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about solving this from the API side? If PHP sends all in the beta information, then we should be fine. And PHP knows whether we are in DEBUG mode or not.

https://github.com/Expensify/Expensify.cash/blob/e28b50e139c492442ea984c3d48e23be744ceb4e/src/libs/Permissions.js#L17

Copy link
Contributor Author

@iwiznia iwiznia May 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is A LOT harder to detect where the request is coming from, from the server than in the client... keep in mind this has to work for contributors that do not point the API to the dev environment, since they don't have one.

@tgolen
Copy link
Contributor

tgolen commented May 26, 2021 via email

@iwiznia iwiznia requested a review from a team as a code owner May 26, 2021 22:20
@iwiznia
Copy link
Contributor Author

iwiznia commented May 26, 2021

Alright, updated

@MelvinBot MelvinBot requested review from jasperhuangg and removed request for a team May 26, 2021 22:20
jasperhuangg
jasperhuangg previously approved these changes May 27, 2021
Copy link
Contributor

@jasperhuangg jasperhuangg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty straightforward and good to me!

marcaaron
marcaaron previously approved these changes May 27, 2021
@@ -0,0 +1,12 @@
import lodashGet from 'lodash/get';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to figure out why this was in it's own file, and then it dawned on me why you did this (and I totally see the logic). I'm not sure it's what we want though. This doesn't really fit our cross-platform pattern because there is a cross-platform module (Environment) that is sharing non-platform specific methods (isDevelopment).

I think rather we should have Environment be non-platform specific and then making only the pieces that need to be platform-specific (getEnvironment in this case) would be split into their platform files.

I hope that makes sense?

@iwiznia iwiznia dismissed stale reviews from marcaaron and jasperhuangg via 256ab7e May 27, 2021 21:31
@iwiznia
Copy link
Contributor Author

iwiznia commented May 27, 2021

Updated and retested

import CONST from '../../CONST';
import getEnvironment from './getEnvironment';

function isDevelopment() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a method doc for the return value.

* @returns {Promise}
*/
function isBetaBuild() {
return new Promise(resolve => resolve(false));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can simply be

Suggested change
return new Promise(resolve => resolve(false));
return Promise.resolve(false);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have to double-check that it works, but I think it does according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve

@@ -11,6 +11,4 @@ function getEnvironment() {
return new Promise(resolve => resolve(lodashGet(Config, 'ENVIRONMENT', CONST.ENVIRONMENT.DEV)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could also use a more simple return Promise.resolve()

@@ -1,7 +1,7 @@
import lodashGet from 'lodash/get';
import Config from 'react-native-config';
import betaChecker from './betaChecker';
import CONST from '../../CONST';
import betaChecker from '../betaChecker/index';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import betaChecker from '../betaChecker/index';
import betaChecker from '../betaChecker';

No need for that. The modules are smart enough to figure it out

@iwiznia
Copy link
Contributor Author

iwiznia commented May 27, 2021

Updated

@marcaaron marcaaron merged commit 81eb997 into main May 27, 2021
@marcaaron marcaaron deleted the ionatan_dev_allbetas branch May 27, 2021 22:53
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants